#
#   此文件定义了压测用户基类的实现，其中定义了supersheeps的所有接口实现
#   注释部分定义了一个压测用户模板，任何项目接入均以此为模板进行开发
#
#
# from sheeps import SheepsUserBase
#
# class User(SheepsUserBase):   #注意，类名不能修改，类模板中的成员函数必须实现
#     def EventStart(self, task):
#         pass
#
#     def EventConnectOpen(self, ip, port, protocol):
#         pass
#
#     def EventConnectMade(self, hsock):
#         pass
#
#     def EventConnectFailed(self, hsock):
#         pass
#
#     def EventConnectClose(self, ip, port, protocol):
#         pass
#
#     def EventConnectClosed(self, hsock):
#         pass
#
#     def EventConnectSend(self, ip, port, content, protocol):
#         pass
#
#     def EventConnectRecved(self, hsock, data):
#         pass
#
#     def EventTimeOut(self):
#         pass
#
#     def EventStop(self, errmsg):
#         pass

import pysheeps


class SheepsUserBase:
    def __init__(self) -> None:
        self.task = None   #存储用户初始化信息

    #日志接口
    def Log(self, loglevel, logstr):
        pysheeps.abi_Log(self, loglevel, logstr)
    #获取一个32位微秒时间
    def Microsecond(self):
        pysheeps.abi_Microsecond()

    #配置相关接口
    def ConfigGetBool(self, section, key, default):
        return pysheeps.abi_ConfigGetBool(section, key, default)

    def ConfigGetNumber(self, section, key, default):
        return pysheeps.abi_ConfigGetNumber(section, key, default)

    def ConfigGetString(self, section, key, default):
        return pysheeps.abi_ConfigGetString(section, key, default)

    #网络连接相关接口
    def SocketConnect(self, ip, port, protocol):
        return pysheeps.abi_SocketConnect(self, ip, port, protocol)

    def SocketSend(self, hsock, data):
        pysheeps.abi_SocketSend(self, hsock, data)

    def SocketClose(self, hsock):
        pysheeps.abi_SocketClose(self, hsock)

    def ScoketPeerAddrGet(self, hsock):
        return pysheeps.abi_SocketPeerAddrGet(self, hsock)

    def SocketPeerAddrSet(self, hsock, ip, port):
        pysheeps.abi_SocketPeerAddrSet(self, hsock, ip, port)
    
    def GetHostByName(name):
        return pysheeps.abi_GetHostByName(name)

    #kcp相关接口
    def KcpCreate(self, hsock, conv, stream_mode=0):
        pysheeps.abi_KcpCreate(hsock, conv, stream_mode)

    def KcpNodelay(self, hsock, nodelay, interval, resend, nc):
        pysheeps.abi_KcpNodelay(hsock, nodelay, interval, resend, nc)

    def KcpWndsize(self, hsock, sndwd, rcvwd):
        pysheeps.abi_KcpWndsize(hsock, sndwd, rcvwd)

    def KcpGetconv(self, hsock):
        return pysheeps.abi_KcpGetconv(hsock)

    def KcpDebug(self, hsock):
        return pysheeps.abi_KcpDebug(hsock)

    #用户回放控制相关接口
    def PlayStop(self):
        pysheeps.abi_PlayStop(self)

    def PlayNormal(self):
        pysheeps.abi_PlayNormal(self)

    def PlayPause(self):
        pysheeps.abi_PlayPause(self)

    def PlayFast(self, fast):
        pysheeps.abi_PlayFast(self, fast)

    def PlayStep(self):
        return pysheeps.abi_PlayStep(self)

    def PlayBack(self, step):
        pysheeps.abi_PlayBack(self, step)

    def PlayStepSession(self):
        return pysheeps.abi_PlayStepSession(self)

    def PlayStepNote(self):
        return pysheeps.abi_PlayStepNote(self)

    def PlayAction(self, action):
        pysheeps.abi_PlayAction(self, action)

    def PlayNoStop(self):
        pysheeps.abi_PlayNoStop(self)

    def PlayOver(self):
        return pysheeps.abi_PlayOver(self)

    #报表相关接口
    def ReportOnline(self):
        pysheeps.abi_ReportOnline(self)

    def ReportOffline(self):
        pysheeps.abi_ReportOffline(self)

    def ReportCounter(self, key, value, report_type, space_time):
        pysheeps.abi_ReportCounter(self, key, value, report_type, space_time)

    def ReportAPIResponse(self, api, response_time):
        pysheeps.abi_ReportAPIResponse(self, api, response_time)

    def ReportAPISend(self, api, flow, count):
        pysheeps.abi_ReportAPISend(self, api, flow, count)
    
    def ReportAPIRecv(self, api, flow, count):
        pysheeps.abi_ReportAPIRecv(self, api, flow, count)

    def ReportOverMessage(self, message):
        pysheeps.abi_ReportOverMessage(self, message)
